package org.wyq.myweb.jmx.service.imple;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.wyq.myweb.jmx.beaninfo.IInfoBean;
import org.wyq.myweb.jmx.service.IMXBeanService;

@Service("gcmx")
@Lazy(true)
public class DefaultGCMBeanService implements IMXBeanService{
	
	List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();

	@Override
	public <T extends IInfoBean> T getInfoBean() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	public static void main(String[] args){
		DefaultGCMBeanService s = new DefaultGCMBeanService();
		for(GarbageCollectorMXBean garbageCollectorMXBean: s.garbageCollectorMXBeans){
			System.out.println(garbageCollectorMXBean.getName());
			System.out.println(garbageCollectorMXBean.getCollectionTime());
			System.out.println(garbageCollectorMXBean.getCollectionCount());
			System.out.println(garbageCollectorMXBean.getObjectName());
			System.out.println(garbageCollectorMXBean.isValid());
			System.out.println(StringUtils.arrayToDelimitedString(garbageCollectorMXBean.getMemoryPoolNames(), ","));
			System.out.println();
		}
	}

}
